<?php
namespace app\middleware;
use think\facade\Db;
//定时发送文章中间件
class SendArticleMiddleware
{
    public function handle($request, \Closure $next)
    {
        $items = Db::name('cms_cache')->where('publish_time','between', [1, time()])->column('cache_id,catid');
        foreach ($items as $item){
            $catid = $item['catid'];
            $cat= $GLOBALS['cat'][$catid];
            $modelid =$cat["modelid"];
            $ModelInfo=$GLOBALS["model"][$modelid];
            //当前模型，用于调用里面的方法
            $model=new \app\admin\model\InfoModel();
            //切换后缀
            $model->setSuffix($cat["table_name"]);
            $model->ModelInfo=$ModelInfo;//向模型里注入当前的模型表信息
            $model->cat=$cat;//向模型里注入当前的栏目信息
            $model->setCheckCache($item['cache_id']);
        }
        return $next($request);
    }
}